package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import controllers.SalonController;

@SuppressWarnings("serial")
public class AbrirMesaServlet extends HttpServlet
{
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.getWriter().append("DOGET");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		int comensales = Integer.parseInt(request.getParameter("comensales"));
		int nroMesa = Integer.parseInt(request.getParameter("mesa"));
		int mozo = Integer.parseInt(request.getParameter("mozo"));
		
		PrintWriter out = response.getWriter();
		out.append(String.valueOf(comensales));
		out.append(String.valueOf(nroMesa));
		out.append(String.valueOf(mozo));
		
		boolean success = SalonController.abrirMesa(nroMesa, comensales, mozo);
		if(success)
		{
			response.sendRedirect("/ad/salon/MesaExito.html");
		}
		else
		{
			response.sendRedirect("/ad/salon/MesaError.html");
		}
	}
}
